*************************************************
* Purpose -- Get and process population data 
* from SEER
************************************************

* RUN 00_path_master.do FIRST TO GET FILEPATHS

***********************************************
* Getting data and saving
***********************************************

infix year 1-4 str state 5-6 statefips 7-8 countyfips 9-11 registry 12-13 race 14 origin 15 sex 16 age 17-18 population 19-26 using "$raw/other/us.1969_2022.19ages.adjusted.txt"

keep if year >= 1980
keep if inrange(age,4,13)

collapse (sum) population, by(statefips countyfips year)

tostring countyfips, replace
tostring statefips, replace

replace countyfips = "00" + countyfips if strlen(countyfips) == 1
replace countyfips = "0" + countyfips if strlen(countyfips) == 2
replace countyfips = statefips + countyfips
rename population pop

destring countyfips, replace
destring statefips, replace

save "$clean/other/county_pop_15_64.dta", replace

